class Solution:
    def perfectMenu(self, materials: List[int], cookbooks: List[List[int]], attribute: List[List[int]],
                    limit: int) -> int:
        n = len(cookbooks)
        res = -1
        for i in range(1, 1 << n):
            s = [0] * 5
            tasty = 0
            energy = 0
            for j in range(n):
                if (i & (1 << j)) != 0:
                    s = [si + mi for si, mi in zip(s, cookbooks[j])]
                    tasty += attribute[j][0]
                    energy += attribute[j][1]
            if energy >= limit and all(si <= mi for si, mi in zip(s, materials)):
                res = max(res, tasty)

        return res